package io.kiki.sba.registry.server.clientInterface.remoting.console.handler;

import io.kiki.sba.registry.api.Channel;
import io.kiki.sba.registry.common.model.GenericResponse;
import io.kiki.sba.registry.common.model.SubscriberUtils;
import io.kiki.sba.registry.common.model.sessionserver.QuerySubscriberRequest;
import io.kiki.sba.registry.common.model.store.Subscriber;
import io.kiki.sba.registry.server.clientInterface.store.Subscribers;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collection;

public class QuerySubscriberRequestHandler extends AbstractConsoleHandler<QuerySubscriberRequest> {
    @Autowired
    protected Subscribers sessionSubscribers;

    @Override
    public Object doHandle(Channel channel, QuerySubscriberRequest request) {
        Collection<Subscriber> subscribers = sessionSubscribers.getSubscriberList(request.getDataInfoId());
        return new GenericResponse().fillSucceed(SubscriberUtils.convert(subscribers));
    }

    @Override
    public Object buildFailedResponse(String msg) {
        return new GenericResponse().fillFailed(msg);
    }

    @Override
    public Class interest() {
        return QuerySubscriberRequest.class;
    }
}
